package com.hzqy.web.vo;

import java.io.Serializable;
import java.util.Map;

public class PagesVo implements Serializable {
	private static final long serialVersionUID = -1600911608142537696L;
	private int pageNo = 1; //当前页码
	private int pageSize = 10; //每页显示条数
	private int totalSize; //总数量
	private int totalPage; //总页数
	private int offset; //偏移量
	private int flag = 0;//0:自动正常翻页，1：滚动翻页
	private int rollSize;//滚动数量
	public int f_ug_type; //分组：1、测试分组；2、免费分组；3、测试+免费；
	
	private Map<String,String> imgMap;//图片
	
	public int getPageNo() {
		if(pageNo <= 0)
			pageNo = 1;
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		if(pageSize <= 0)
			pageSize = 10;
		this.pageSize = pageSize;
	}
	public int getTotalSize() {
		return totalSize;
	}
	public void setTotalSize(int totalSize) {
		if(flag == 0){
			totalPage = getNormalTotalPage(totalSize);
			if(totalPage<pageNo) //如果总页数小于页面上输入框的页数，则页面数变为最后一页
				pageNo = totalPage;
			setOffset((getPageNo()-1)*getPageSize());
		}else if(flag == 1){
			totalPage = getHandTotalPage(totalSize);
			setOffset((getPageNo()-1)*rollSize);
		}
		this.totalSize = totalSize;
	}
	public int getTotalPage() {
		if(flag == 1){
			return getHandTotalPage(this.totalSize);
		}else{
			return getNormalTotalPage(this.totalSize);
		}
		
	}
	/**
	 * 普通翻页
	 * @return
	 */
	private int getNormalTotalPage(int totalSize){
		int totalPage = 0; //总页数
		if(totalSize%pageSize > 0){
			totalPage = totalSize/pageSize+1;
		}else{
			totalPage = totalSize/pageSize;
		}
		if(totalPage == 0){
			totalPage = 1;
		}
		return totalPage;
	}
	//滚动翻页
	private int getHandTotalPage(int totalSize){
		int totalPage = 0; //总页数
		if(totalSize%rollSize > 0){
			totalPage = totalSize/rollSize+1;
		}else{
			totalPage = totalSize/rollSize;
		}
		if(totalPage == 0 || totalPage < pageSize/rollSize){
			totalPage = 1;
		}else{
			totalPage = totalPage - pageSize/rollSize + 1;
		}
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getOffset() {
		return offset;
	}
	public void setOffset(int offset) {
		this.offset = offset;
	}
	public int getF_ug_type() {
		return f_ug_type;
	}
	public void setF_ug_type(int f_ug_type) {
		this.f_ug_type = f_ug_type;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public int getRollSize() {
		return rollSize;
	}
	public void setRollSize(int rollSize) {
		this.flag = 1;
		this.rollSize = rollSize;
	}
	public Map<String, String> getImgMap() {
		return imgMap;
	}
	public void setImgMap(Map<String, String> imgMap) {
		this.imgMap = imgMap;
	}
	
}
